//
//  ZYCStuLeaveRecordCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/26.
//

#import "ZYCStuLeaveRecordCell.h"
#import "ZYCLeaveRecordModel.h"
@interface ZYCStuLeaveRecordCell ()


@property (nonatomic, strong) UIView *bgWhiteView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *leaveTimeLabel;
@property (nonatomic, strong) UILabel *leaveStatusLabel;

@end

@implementation ZYCStuLeaveRecordCell

- (void)setModel:(ZYCLeaveRecordModel *)model{
    _model = model;
    _titleLabel.text = model.leaveTitle;
    _timeLabel.text = model.submitTime;
    _leaveTimeLabel.text = [NSString stringWithFormat:@"请假日期:%@",model.leaveDate];
    NSInteger type = [model.durationLeave integerValue];
    _leaveStatusLabel.text = model.durationLeaveName;
    
    //请假时长（1：上午假；2：下午假；3：全天假）
    if (type == 1) {//上午假
        _leaveStatusLabel.textColor = HEX_RGB(@"#39A85B");
        _leaveStatusLabel.layer.borderColor = HEX_RGB(@"#39A85B").CGColor;
    }else if(type == 2){//下午假
        _leaveStatusLabel.textColor = HEX_RGB(@"#395AD2");
        _leaveStatusLabel.layer.borderColor = HEX_RGB(@"#395AD2").CGColor;
    }else{// 全天假
        _leaveStatusLabel.textColor = HEX_RGB(@"#EB9F28");
        _leaveStatusLabel.layer.borderColor = HEX_RGB(@"#EB9F28").CGColor;
    }

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgWhiteView];
        [self.bgWhiteView addSubview:self.titleLabel];
        [self.bgWhiteView addSubview:self.line];
        [self.bgWhiteView addSubview:self.timeLabel];
        [self.bgWhiteView addSubview:self.leaveTimeLabel];
        [self.bgWhiteView addSubview:self.leaveStatusLabel];

        [self.bgWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(9.5f);
            make.right.equalTo(self.contentView).offset(-9.5f);
            make.top.bottom.equalTo(self.contentView);
        }];
        
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.mas_lessThanOrEqualTo(self.timeLabel.mas_left).offset(-5.0f);
            make.top.equalTo(self.bgWhiteView).offset(10.0f);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgWhiteView).offset(-19.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(8.5f);
            make.height.mas_equalTo(1.0f);
        }];
        
        
        [self.leaveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(19.0f);
            make.bottom.equalTo(self.bgWhiteView).offset(-10.5f);
        }];
        
        [self.leaveStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgWhiteView).offset(-19.0f);
            make.centerY.equalTo(self.leaveTimeLabel);
            make.width.mas_equalTo(57.0f);
            make.height.mas_equalTo(24.0f);
        }];
        
        [self.timeLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    }
    return self;
}

- (UIView *)bgWhiteView {
    if (!_bgWhiteView) {
        _bgWhiteView = [[UIView alloc] init];
        _bgWhiteView.backgroundColor = HEX_RGB(@"#FFFFFF");
        _bgWhiteView.layer.cornerRadius = 7.5;
        _bgWhiteView.layer.masksToBounds = YES;
    }
    return _bgWhiteView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}

- (UILabel *)leaveTimeLabel {
    if (!_leaveTimeLabel) {
        _leaveTimeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _leaveTimeLabel;
}

- (UILabel *)leaveStatusLabel {
    if (!_leaveStatusLabel) {
        _leaveStatusLabel = [[UILabel alloc] init];
        _leaveStatusLabel.layer.borderWidth = 1.0f;
        _leaveStatusLabel.layer.cornerRadius = 11.5;
        _leaveStatusLabel.layer.masksToBounds = YES;
        _leaveStatusLabel.font = kCustomFont(@"PingFangSC-Light", 14);
        _leaveStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _leaveStatusLabel;
}


- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

@end
